/*    */ package com.lmpop.trade.uploadFile;
/*    */ 
/*    */ import com.sun.image.codec.jpeg.JPEGCodec;
/*    */ import com.sun.image.codec.jpeg.JPEGImageEncoder;
/*    */ import java.awt.Graphics;
/*    */ import java.awt.Image;
/*    */ import java.awt.image.BufferedImage;
/*    */ import java.io.File;
/*    */ import java.io.FileOutputStream;
/*    */ import java.io.IOException;
/*    */ import javax.imageio.ImageIO;
/*    */ 
/*    */ public class ImageUtil
/*    */ {
/*    */   private String srcFile;
/*    */   private String destFile;
/*    */   private int width;
/*    */   private int height;
/*    */   private Image img;
/*    */ 
/*    */   public ImageUtil(String srcFile)
/*    */     throws IOException
/*    */   {
/* 16 */     File _file = new File(srcFile);
/* 17 */     this.srcFile = srcFile;
/* 18 */     this.destFile = srcFile;
/* 19 */     this.img = ImageIO.read(_file);
/* 20 */     this.width = this.img.getWidth(null);
/* 21 */     this.height = this.img.getHeight(null);
/*    */   }
/*    */ 
/*    */   public void resize(int w, int h) throws IOException {
/* 25 */     BufferedImage _image = new BufferedImage(w, h, 1);
/* 26 */     _image.getGraphics().drawImage(this.img, 0, 0, w, h, null);
/* 27 */     FileOutputStream out = new FileOutputStream(this.destFile);
/* 28 */     JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
/* 29 */     encoder.encode(_image);
/* 30 */     out.close();
/*    */   }
/*    */ 
/*    */   public void resize(double t) throws IOException {
/* 34 */     int w = (int)(this.width * t);
/* 35 */     int h = (int)(this.height * t);
/* 36 */     resize(w, h);
/*    */   }
/*    */ 
/*    */   public void resizeByWidth(int w) throws IOException {
/* 40 */     int h = this.height * w / this.width;
/* 41 */     resize(w, h);
/*    */   }
/*    */ 
/*    */   public void resizeByHeight(int h) throws IOException {
/* 45 */     int w = this.width * h / this.height;
/* 46 */     resize(w, h);
/*    */   }
/*    */ 
/*    */   public void resizeFix(int w, int h) throws IOException {
/* 50 */     if (this.width / this.height > w / h)
/* 51 */       resizeByWidth(w);
/*    */     else
/* 53 */       resizeByHeight(h);
/*    */   }
/*    */ 
/*    */   public void setDestFile(String df)
/*    */   {
/* 58 */     this.destFile = df;
/*    */   }
/*    */ 
/*    */   public int getSrcWidth()
/*    */   {
/* 63 */     return this.width;
/*    */   }
/*    */ 
/*    */   public int getSrcHeight() {
/* 67 */     return this.height;
/*    */   }
/*    */ }

/* Location:           F:\电商\commons-utils.jar
 * Qualified Name:     com.lmpop.trade.uploadFile.ImageUtil
 * JD-Core Version:    0.6.0
 */